package com.ruoyi.performance.service.impl;


import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.ruoyi.performance.mapper.PerfCheckresultMapper;
import com.ruoyi.performance.domain.PerfCheckresult;
import com.ruoyi.performance.service.IPerfCheckresultService;
import com.ruoyi.common.constant.Constants;
import com.ruoyi.common.core.text.Convert;
import com.ruoyi.common.utils.ServletUtils;


/**
 * 绩效打分Service业务层处理
 * 
 * @author ygx
 * @date 2020-09-03
 */
@Service
public class PerfCheckresultServiceImpl implements IPerfCheckresultService 
{
    @Autowired
    private PerfCheckresultMapper perfCheckresultMapper;
    

    /**
     * 查询绩效打分
     * 
     * @param perfcheckresultId 绩效打分ID
     * @return 绩效打分
     */
    @Override
    public PerfCheckresult selectPerfCheckresultById(Long perfcheckresultId)
    {
        return perfCheckresultMapper.selectPerfCheckresultById(perfcheckresultId);
    }

    /**
     * 查询绩效打分列表
     * 
     * @param perfCheckresult 绩效打分
     * @return 绩效打分
     */
    @Override
    public List<PerfCheckresult> selectPerfCheckresultList(PerfCheckresult perfCheckresult)
    {
        return perfCheckresultMapper.selectPerfCheckresultList(perfCheckresult);
    }
    
    
 
    /**
     * 新增绩效打分
     * 
     * @param perfCheckresult 绩效打分
     * @return 结果
     */
    @Override
    public int insertPerfCheckresult(PerfCheckresult perfCheckresult)
    {
        return perfCheckresultMapper.insertPerfCheckresult(perfCheckresult);
    }

    /**
     * 修改绩效打分
     * 
     * @param perfCheckresult 绩效打分
     * @return 结果
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public int updatePerfCheckresult(Map<String,List<PerfCheckresult>> datas)
    {   
    	int result = 1;
    	HttpServletRequest request = ServletUtils.getRequest();
		String username = request.getHeader(Constants.CURRENT_USERNAME);
		String datedate = new SimpleDateFormat("yyyyMMdd").format(new Date());
		String datetime = new SimpleDateFormat("HHmmss").format(new Date());
		for (PerfCheckresult perfCheckresult : datas.get("datas"))
		{
		perfCheckresult.setLogdate(Long.valueOf(datedate));
		perfCheckresult.setLogtime(Long.valueOf(datetime));
		perfCheckresult.setLoguser(username);
        perfCheckresultMapper.updatePerfCheckresult(perfCheckresult);
		}
        return result;
    }

    /**
     * 删除绩效打分对象
     * 
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deletePerfCheckresultByIds(String ids)
    {
        return perfCheckresultMapper.deletePerfCheckresultByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除绩效打分信息
     * 
     * @param perfcheckresultId 绩效打分ID
     * @return 结果
     */
    public int deletePerfCheckresultById(Long perfcheckresultId)
    {
        return perfCheckresultMapper.deletePerfCheckresultById(perfcheckresultId);
    }
    

}
